package org.malred.hotelsystem.fragment.user;

import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.malred.hotelsystem.R;
import org.malred.hotelsystem.activities.user.UserHotelDetailActivity;
import org.malred.hotelsystem.adapter.HotelRecycleAdapter;
import org.malred.hotelsystem.adapter.UserHotelRecycleAdapter;
import org.malred.hotelsystem.dao.HotelDao;
import org.malred.hotelsystem.fragment.BaseFragment;
import org.malred.hotelsystem.model.entity.HotelEntity;

import java.util.List;

/**
 * 用户系统 - 房间页
 */
public class UserHomeFragment extends BaseFragment {
    RecyclerView rv;
    private List<HotelEntity> hotelEntities;
    private UserHotelRecycleAdapter adapter;

    @Override
    protected int setLayoutResourceID() {
        return R.layout.fragment_user_home;
    }

    @Override
    protected void setUpView() {
        rv = getContentView().findViewById(R.id.user_home_rv);
    }

    @Override
    protected void setUpData() {
        hotelEntities = HotelDao.getAll(getDb());

//        adapter = new HotelRecycleAdapter(getMContext(), hotelEntities);
        adapter = new UserHotelRecycleAdapter(getMContext(), hotelEntities);
        rv.setAdapter(adapter);
        // recycle view 显示方式(布局)
        GridLayoutManager manager = new GridLayoutManager(getMContext(),
                // 参数2: 列数; 参数3: 垂直排列; 参数4: 不反转排列
                2, GridLayoutManager.VERTICAL, false);
        rv.setLayoutManager(manager);
    }
}